/**
 * 图片处理Api
 * Author: david.deng<david.deng@jcinfotech.com>
 * Date: 2019/02/15
 */
import type { JCRequestOption } from '../ServiceBase';
import { ServiceBase } from '../ServiceBase';
import { ApiPre } from '../../config';

const urlbase = `${ApiPre}/Image`;

export class ImageService extends ServiceBase {
  /**
   * 获取base64图片,符合前端img格式展示
   */
  GetImage(imageId: string, option: JCRequestOption = {}) {
    return this.request<string>(`${urlbase}/GetImage`, { imageId }, option);
  }

  /**
   * 获取图片对象
   */
  GetImageOfObject(imageId: string, option: JCRequestOption = {}) {
    return this.request<ImageEm>(`${urlbase}/GetImageOfObject`, { imageId }, option);
  }

  /**
   * 获取图片文件
   */
  GetImageFile(imageId: string, option: JCRequestOption = {}) {
    return this.request<any>(`${urlbase}/GetImageFile`, { imageId }, option);
  }

  /**
   * 保存图片
   */
  SaveImage(data: ImageEm, option: JCRequestOption = {}) {
    return this.request<string>(`${urlbase}/SaveImage`, { data }, option);
  }

  SaveImageToFile(data: ImageEm, option: JCRequestOption = {}) {
    return this.request<string>(`${urlbase}/SaveImageToFile`, { data }, option);
  }

  DeleteImage(imgId: string, option: JCRequestOption = {}) {
    return this.request<boolean>(`${urlbase}/DeleteImage`, { imgId }, option);
  }

  ImageUploadToOss(option: JCRequestOption = {}) {
    return this.request<string>('/B2CBG/AliOss/SaveFile', null, option);
  }
}

export class ImageEm {
  ImageId = '';
  /**
   * 图片数据base64位,为前端展示格式
   */
  Data = '';
  /**
   * 外部系统URL,本系统不会再进行处理
   */
  ImgUrl = '';
  /**
   * 微信的临时媒体ID,本系统会将文件获取后进行保存,需要依赖微信系统以及登录信息,不可随便用
   */
  WxMediaId = '';
  /**
   * 微信APPID
   */
  WxAppId = '';

  Type = '';

  Module = '';

  Remark = '';
}
